fix(provider): honor base_url for google-genai and vertexai providers - #1269
Conversation
The google-genai and vertexai provider types silently ignored a configured base_url and always hit generativelanguage.googleapis.com (e.g. a Gemini- compatible proxy URL + key could not be used). Plumb the endpoint through to the @google/genai SDK via httpOptions.baseUrl: - kosong: add baseUrl to GoogleGenAIOptions and inject it into the client's httpOptions alongside the existing headers (the SDK merges headers and overrides the base host). - agent-core: forward provider.baseUrl in the google-genai and vertexai branches, with GOOGLE_GEMINI_BASE_URL / GOOGLE_VERTEX_BASE_URL env fallback. vertexai keeps deriving location from an aiplatform host. - docs: document base_url for both providers, noting the host root only must be given because the SDK appends the API version itself. Covered by unit tests asserting the URL reaches the kosong config and the SDK client's httpOptions.
🦋 Changeset detectedLatest commit: 9682bc0 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 433a782dc5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The vertexai branch forwarded the endpoint from config `base_url` OR the GOOGLE_VERTEX_BASE_URL env fallback, but service-account detection (`hasVertexAIServiceEnv` / `vertexAILocation`) still derived the region from `provider.baseUrl` only. Supplying the regional endpoint via the env fallback (with a project but no explicit GOOGLE_CLOUD_LOCATION) therefore left location undefined and silently downgraded Vertex ADC to API-key Gemini routing. Resolve the effective base URL once and use it for both forwarding and location derivation, so the env fallback behaves exactly like `base_url`. Add a changeset for the kosong + agent-core patch release.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
The
google-genaiandvertexaiprovider types silently ignored a configuredbase_url— requests always hitgenerativelanguage.googleapis.com. For example, a "Gemini-compatible proxy URL + key" setup was unusable.The endpoint was dropped at two layers:
GoogleGenAIOptionshad nobaseUrlfield, and_buildClientnever passedhttpOptions.baseUrlto the@google/genaiSDK.toKosongProviderConfignever readprovider.baseUrlin thegoogle-genaibranch; thevertexaibranch only mined it forlocation, never as an endpoint.By contrast, the
openai/anthropic/kimi/openai_responsesbranches all readbase_urlcorrectly.Changes
providers/google-genai.ts): addbaseUrltoGoogleGenAIOptions, store it on the instance, and inject it into the client'shttpOptions.baseUrl, merged with the existingheadersinto a singlehttpOptions(the SDK merges headers and overrides the base host, so both coexist).session/provider-manager.ts): forwardprovider.baseUrlin thegoogle-genaiandvertexaibranches, withGOOGLE_GEMINI_BASE_URL/GOOGLE_VERTEX_BASE_URLenv fallback.vertexaikeeps derivinglocationfrom an aiplatform host (backward compatible).base_urlfor both providers in the EN/ZHproviders.md, noting that only the host root should be given — the SDK appends the API version segment itself (Gemini/v1beta, Vertex/v1beta1), so a trailing version would duplicate the path (/v1beta/v1beta/...).Testing
Added 8 unit tests:
baseUrlreaches the SDK client'shttpOptions, coexists withdefaultHeaders, and applies in vertexai mode.base_urlis forwarded into the kosong config, the env fallback works, and vertexai still deriveslocationfrom an aiplatform host.Also ran smoke verification (intercepting the real global
fetch, driving a fullgenerate()): confirmed the configuredbase_urlreaches the actual outbound request URL and hits the custom host, with no regression to the default endpoint when unset.typecheckpass; 0 lint errors on changed files